/**
 * 
 */
package org.statewalker.template.dom;

import java.util.List;

import org.statewalker.template.XmlTemplateRunner.XmlDataAccessor;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class DomDataAccessor extends XmlDataAccessor<Node> {

    public DomDataAccessor() {
        super(new DomAccessor());
    }

    @Override
    public void loadData(List<Node> input, String link, List<Node> output) {
        if (link.startsWith("@")) {
            link = link.substring(1);
            for (Node node : input) {
                if (!(node instanceof Element))
                    continue;
                Element e = (Element) node;
                Attr attr = e.getAttributeNode(link);
                if (attr != null)
                    output.add(attr);
            }
        } else {
            super.loadData(input, link, output);
        }
    }
}